namespace Delphi.Mimir.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class AddManagedProduct : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "fin.pfm_asset_universes",
                c => new
                    {
                        asu_id = c.Int(nullable: false, identity: true),
                        asu_include_fg = c.Boolean(nullable: false),
                        asu_mpd_id = c.Int(nullable: false),
                        asu_sym_id = c.Int(),
                        asu_exc_id = c.Int(),
                        asu_valid_frm_dt = c.DateTime(nullable: false),
                        asu_valid_til_dt = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.asu_id)
                .ForeignKey("fin.eod_exchanges", t => t.asu_exc_id)
                .ForeignKey("fin.pfm_managed_products", t => t.asu_mpd_id, cascadeDelete: true)
                .ForeignKey("fin.eod_symbols", t => t.asu_sym_id)
                .Index(t => t.asu_mpd_id)
                .Index(t => t.asu_sym_id)
                .Index(t => t.asu_exc_id);
            
            CreateTable(
                "fin.pfm_managed_products",
                c => new
                    {
                        mpd_id = c.Int(nullable: false),
                        mpd_sym_id = c.Int(nullable: false),
                        mpd_managed_fg = c.Boolean(),
                        mpd_valid_frm_dt = c.DateTime(nullable: false),
                        mpd_valid_til_dt = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.mpd_id)
                .ForeignKey("fin.eod_symbols", t => t.mpd_id, cascadeDelete: true)
                .Index(t => t.mpd_id);
            
            CreateTable(
                "fin.pfm_managed_prod_positions",
                c => new
                    {
                        mpp_id = c.Int(nullable: false, identity: true),
                        mpp_mpd_id = c.Int(nullable: false),
                        mpp_sym_id = c.Int(nullable: false),
                        mpp_quantity = c.Int(nullable: false),
                        mpp_valid_frm_dt = c.DateTime(nullable: false),
                        mpp_valid_til_dt = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.mpp_id)
                .ForeignKey("fin.eod_symbols", t => t.mpp_sym_id)
                .ForeignKey("fin.pfm_managed_products", t => t.mpp_mpd_id, cascadeDelete: true)
                .Index(t => t.mpp_mpd_id)
                .Index(t => t.mpp_sym_id);
            
            CreateTable(
                "fin.pfm_orders",
                c => new
                    {
                        mpo_id = c.Int(nullable: false, identity: true),
                        mpo_mpd_id = c.Int(nullable: false),
                        mpo_sym_id = c.Int(nullable: false),
                        mpo_quantity = c.Int(nullable: false),
                        mpo_entry_dt = c.DateTime(nullable: false),
                        mpo_valid_frm_dt = c.DateTime(nullable: false),
                        mpo_valid_til_dt = c.DateTime(),
                        mpo_moc_id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.mpo_id)
                .ForeignKey("fin.pfm_order_constraints", t => t.mpo_moc_id, cascadeDelete: true)
                .ForeignKey("fin.eod_symbols", t => t.mpo_sym_id, cascadeDelete: true)
                .ForeignKey("fin.pfm_managed_products", t => t.mpo_mpd_id)
                .Index(t => t.mpo_mpd_id)
                .Index(t => t.mpo_sym_id)
                .Index(t => t.mpo_moc_id);
            
            CreateTable(
                "fin.pfm_order_constraints",
                c => new
                    {
                        moc_id = c.Int(nullable: false, identity: true),
                        moc_cd = c.String(nullable: false),
                        moc_desc = c.String(nullable: false),
                    })
                .PrimaryKey(t => t.moc_id);
            
            CreateTable(
                "fin.pfm_order_executions",
                c => new
                    {
                        moe_id = c.Int(nullable: false, identity: true),
                        moe_mpo_id = c.Int(nullable: false),
                        moe_ts = c.DateTime(nullable: false),
                        moe_amount = c.Int(nullable: false),
                        moe_partial_fg = c.Boolean(nullable: false),
                        moe_quote = c.Decimal(nullable: false, precision: 18, scale: 6),
                        moe_fees = c.Decimal(nullable: false, precision: 18, scale: 6),
                    })
                .PrimaryKey(t => t.moe_id)
                .ForeignKey("fin.pfm_orders", t => t.moe_mpo_id, cascadeDelete: true)
                .Index(t => t.moe_mpo_id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("fin.pfm_asset_universes", "asu_sym_id", "fin.eod_symbols");
            DropForeignKey("fin.pfm_managed_products", "mpd_id", "fin.eod_symbols");
            DropForeignKey("fin.pfm_orders", "mpo_mpd_id", "fin.pfm_managed_products");
            DropForeignKey("fin.pfm_orders", "mpo_sym_id", "fin.eod_symbols");
            DropForeignKey("fin.pfm_order_executions", "moe_mpo_id", "fin.pfm_orders");
            DropForeignKey("fin.pfm_orders", "mpo_moc_id", "fin.pfm_order_constraints");
            DropForeignKey("fin.pfm_managed_prod_positions", "mpp_mpd_id", "fin.pfm_managed_products");
            DropForeignKey("fin.pfm_managed_prod_positions", "mpp_sym_id", "fin.eod_symbols");
            DropForeignKey("fin.pfm_asset_universes", "asu_mpd_id", "fin.pfm_managed_products");
            DropForeignKey("fin.pfm_asset_universes", "asu_exc_id", "fin.eod_exchanges");
            DropIndex("fin.pfm_order_executions", new[] { "moe_mpo_id" });
            DropIndex("fin.pfm_orders", new[] { "mpo_moc_id" });
            DropIndex("fin.pfm_orders", new[] { "mpo_sym_id" });
            DropIndex("fin.pfm_orders", new[] { "mpo_mpd_id" });
            DropIndex("fin.pfm_managed_prod_positions", new[] { "mpp_sym_id" });
            DropIndex("fin.pfm_managed_prod_positions", new[] { "mpp_mpd_id" });
            DropIndex("fin.pfm_managed_products", new[] { "mpd_id" });
            DropIndex("fin.pfm_asset_universes", new[] { "asu_exc_id" });
            DropIndex("fin.pfm_asset_universes", new[] { "asu_sym_id" });
            DropIndex("fin.pfm_asset_universes", new[] { "asu_mpd_id" });
            DropTable("fin.pfm_order_executions");
            DropTable("fin.pfm_order_constraints");
            DropTable("fin.pfm_orders");
            DropTable("fin.pfm_managed_prod_positions");
            DropTable("fin.pfm_managed_products");
            DropTable("fin.pfm_asset_universes");
        }
    }
}
